package com.ruoyi.common.utils.aspose;

import org.apache.commons.io.FilenameUtils;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * File工厂类，用于分发不同类型文件
 *
 * @author ysz
 * @date 2024/1/31 19:09
 */
public class FileFactory {
    static Map<String, FileWrapper> FILE_TYPE = Map.of(
            "doc",new DocWrapper(),
            "docx",new DocWrapper(),
            "md",new MarkDownWrapper(),
            "pdf", new PdfWrapper()
    );

    public FileContentEntity chooseFileTypeConvertToHtml(MultipartFile multipartFile) throws Exception {
        FileWrapper fileUtil = FILE_TYPE.get(FilenameUtils.getExtension(multipartFile.getOriginalFilename()));
        return fileUtil.convertToHtmlContent(multipartFile);
    }
}
